<template>
    <div class="right-top-container">
        <div class="progress-list">
            <div class="progress-header">
                <span class="header-text">电池数/满电数</span>
            </div>
            <!-- <div class="progress-subtitle">
                <span>电池数，满电数（效果如下，底条表示电池数，绿条表示满电数）</span>
            </div> -->
            <div class="progress-items" style="height: calc(100% - 20px);">
                <ProgressView :progressData="progressData"></ProgressView>
                <!-- <div v-for="(item, index) in progressData" :key="index" class="progress-item">
                    <div class="item-info">
                        <span class="item-number">{{ index + 1 }}.</span>
                        <span class="item-name">{{ item.name }}</span>
                        <span class="item-value">{{ item.value }} kwh</span>
                    </div>
                    <div class="progress-bar-container">
                        <el-progress :percentage="item.percentage" :stroke-width="20" :show-text="false" color="#4ade80"
                            track-color="#374151" />
                    </div>
                </div> -->
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import ProgressView from "@/components/progressView/index.vue";

interface ProgressDataItem {
    name: string
    value: number
    valueB: number
    unit: string
    description: string
    type: number
    color: string
}

const progressData = ref<ProgressDataItem[]>([])

// 初始化函数
const init = (module: any) => {
    console.log('Module5 初始化完成')
    let obj = JSON.parse(module)
    let list: any[] = [] 
    if(module){
        obj.forEach((item: any) => {
            list.push({
                name: item.cabinetName,
                value: Number(item.batteryCount),
                valueB: 11,
                unit: '个',
                description: '电池数',
                type: 1,
                color: '#4ade80'
            })
        })
        progressData.value = list
    }
}

// 暴露初始化函数
defineExpose({
    init
})
</script>

<style scoped lang="less">
.right-top-container {
    width: 100%;
    height: 100%;
    padding: 15px;
    box-sizing: border-box;
    background: #1e293b;
    border-radius: 8px;
}

.progress-list {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.progress-header {
    margin-bottom: 8px;
    height: 20px;
    .header-text {
        color: #e2e8f0;
        font-size: 14px;
        font-weight: 500;
        line-height: 1.4;
    }
}

.progress-subtitle {
    margin-bottom: 20px;

    span {
        color: #94a3b8;
        font-size: 12px;
        line-height: 1.4;
    }
}

.progress-items {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.progress-item {
    display: flex;
    flex-direction: column;
    gap: 8px;

    .item-info {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .item-number {
            color: #e2e8f0;
            font-size: 14px;
            font-weight: 600;
            min-width: 20px;
        }

        .item-name {
            color: #e2e8f0;
            font-size: 14px;
            flex: 1;
            margin-left: 8px;
        }

        .item-value {
            color: #e2e8f0;
            font-size: 14px;
            font-weight: 600;
        }
    }

    .progress-bar-container {
        width: 100%;

        :deep(.el-progress-bar__outer) {
            background-color: #374151 !important;
            border-radius: 10px;
        }

        :deep(.el-progress-bar__inner) {
            background: linear-gradient(90deg, #22c55e 0%, #4ade80 100%) !important;
            border-radius: 10px;
        }
    }
}
</style>